using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Admin_Admin_Stock_StockNumberDetail : Admin, IRequiresSessionState
{
	protected Literal ltrTitle;
	protected HtmlTable table_item;
	protected TextBox txtSearchBeginDate;
	protected TextBox txtSearchEndDate;
	protected TextBox txtSearchInfoNumber;
	protected Button btnSearch;
	protected Repeater rptList;
	protected Literal ltrPagePanel;
	private string linkHead = "";
	private string beforeUrl = "Admin_Stock_StockNumberDetail.aspx?MenuID=5&MenuName=库存管理&FileName=库存明细信息";
	private int productID = 0;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	public int ProductID
	{
		get
		{
			if (base.Request.QueryString["ProductID"] != null)
			{
				this.productID = Convert.ToInt32(base.Request.QueryString["ProductID"].Trim());
			}
			return this.productID;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(45))
			{
				base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "Admin_Stock_StockNumberDetail");
				base.WriteRightErrMsg();
			}
			this.BindData();
		}
	}
	protected string GetQuery()
	{
		string text = " where (StockStatus=1 or StockStatus=3) and StockOrderType<>'xsgjd'";
		if (this.ProductID > 0)
		{
			text = text + " and  ProductID=" + this.ProductID;
		}
		string text2 = Fetch.Get("BeginTime");
		if (!string.IsNullOrEmpty(text2))
		{
			this.txtSearchBeginDate.Text = text2;
		}
		else
		{
			text2 = this.txtSearchBeginDate.Text;
		}
		if (!string.IsNullOrEmpty(text2))
		{
			text = text + " and DATEDIFF(DD, StockDate,'" + text2 + "')<=0";
			this.linkHead = this.linkHead + "&BeginTime=" + text2;
		}
		string text3 = Fetch.Get("EndTime");
		if (!string.IsNullOrEmpty(text3))
		{
			this.txtSearchEndDate.Text = text3;
		}
		else
		{
			text3 = this.txtSearchEndDate.Text;
		}
		if (!string.IsNullOrEmpty(text3))
		{
			if (!string.IsNullOrEmpty(text2))
			{
				if (Convert.ToDateTime(text2) > Convert.ToDateTime(text3))
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
				}
			}
			text = text + "and DATEDIFF(DD, StockDate,'" + text3 + "')>=0";
			this.linkHead = this.linkHead + "&EndTime=" + text3;
		}
		string text4 = Fetch.Get("InfoNumber");
		if (!string.IsNullOrEmpty(text4))
		{
			this.txtSearchInfoNumber.Text = text4;
		}
		else
		{
			text4 = this.txtSearchInfoNumber.Text;
		}
		if (!string.IsNullOrEmpty(text4))
		{
			text = text + " and InfoNumber like '%" + text4 + "%'";
			this.linkHead = this.linkHead + "&InfoNumber=" + text4;
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		string result = "order by ProductID desc";
		string value = this.txtSearchBeginDate.Text.Trim();
		string value2 = this.txtSearchEndDate.Text.Trim();
		if (!string.IsNullOrEmpty(value) || !string.IsNullOrEmpty(value2))
		{
			result = "order by StockDate desc";
		}
		return result;
	}
	public void BindData()
	{
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		int num = 0;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		int num2 = 10;
		int listInfoItemProductRecordCount = BLLInstance.BllStockInfoOrder.GetListInfoItemProductRecordCount(query);
		int startIndex = (num - 1) * num2 + 1;
		int endIndex = num * num2;
		DataTable listInfoItemProductPage = BLLInstance.BllStockInfoOrder.GetListInfoItemProductPage(query, queryByOrder, startIndex, endIndex);
		this.rptList.DataSource = listInfoItemProductPage;
		this.rptList.DataBind();
		decimal d = 0m;
		decimal d2 = 0m;
		for (int i = 0; i < this.rptList.Items.Count; i++)
		{
			int num3 = i + 1;
			if (num > 0)
			{
				num3 = (num - 1) * num2 + num3;
			}
			Label label = (Label)this.rptList.Items[i].FindControl("lblRow");
			label.Text = num3.ToString();
			HiddenField hiddenField = (HiddenField)this.rptList.Items[i].FindControl("hfCount");
			HiddenField hiddenField2 = (HiddenField)this.rptList.Items[i].FindControl("hfStandPrice");
			Label label2 = (Label)this.rptList.Items[i].FindControl("lblMoney");
			HiddenField hiddenField3 = (HiddenField)this.rptList.Items[i].FindControl("hfStockStatus");
			Label label3 = (Label)this.rptList.Items[i].FindControl("lblStockCount");
			if (label2 != null)
			{
				if (!string.IsNullOrEmpty(hiddenField.Value) && !string.IsNullOrEmpty(hiddenField2.Value))
				{
					decimal d3 = Convert.ToDecimal(hiddenField2.Value);
					int value = 0;
					if (hiddenField3.Value == "1")
					{
						value = Convert.ToInt32(hiddenField.Value);
					}
					else
					{
						if (hiddenField3.Value == "3")
						{
							value = -Convert.ToInt32(hiddenField.Value);
						}
					}
					label3.Text = value.ToString();
					decimal d4 = d3 * value;
					label2.Text = d4.ToString();
					d2 += d4;
					d += value;
				}
			}
		}
		Label label4 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalCount");
		Label label5 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalMoney");
		label4.Text = d.ToString();
		label5.Text = d2.ToString();
		string url = string.Concat(new object[]
		{
			this.beforeUrl,
			"&ProductID=",
			this.ProductID,
			this.linkHead,
			"&pageindex"
		});
		this.ltrPagePanel.Text = CurrPageLinks.instance.CurrPageLinkStr(num, num2, listInfoItemProductRecordCount, "条记录&nbsp;每页" + num2 + "条记录&nbsp;", url, true);
	}
	protected void btnSearch_Click(object sender, EventArgs e)
	{
		this.BindData();
	}
}
